package com.cf.cf455A;

import java.util.*;


public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		HashMap<Integer, Long> mp = new HashMap<>();
		int ma = 0;
		for (int i = 0; i < n; i ++) {
			p[i] = sc.nextInt();
			ma = Math.max(ma, p[i]);
			mp.put(p[i], mp.getOrDefault(p[i], 0L) + 1);
		}

		
		long[] f = new long[ma + 1];
		f[1] = mp.getOrDefault(1, 0L);
		for (int i = 2; i <= ma; i ++) {
			f[i] = Math.max(f[i - 1], i * mp.getOrDefault(i, 0L) + f[i - 2]);
		}
		
		System.out.println(f[ma]);
		sc.close();
	}

}
